package middleWare

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func CORSMiddleware() gin.HandlerFunc{
	return func(ctx *gin.Context){
		ctx.Writer.Header().Set("Access-Control-Allow-Origin","http://localhost:8080")//允许8080
		ctx.Writer.Header().Set("Access-Control-Max-Age","8640") //缓存时间
		ctx.Writer.Header().Set("Access-Control-Allow-Methods","*")
		ctx.Writer.Header().Set("Access-Control-Allow-Headers","*")
		ctx.Writer.Header().Set("Access-Control-Allow-Credentials","true")
		if ctx.Request.Method == http.MethodOptions{
			ctx.AbortWithStatus(200)
		}else{
			ctx.Next()
		}
	}
}
